/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * AddTablePanel.java
 *
 * Created on Sep 20, 2010, 12:11:13 AM
 */
package project.jpdftools.ui;

import java.awt.Toolkit;
import java.util.logging.Level;
import project.jpdftools.managers.LocalizationManager;
import project.jpdftools.managers.LoggerManager;
import project.jpdftools.ui.logic.JPDFTable;

/**
 *
 * @author Mido
 */
public class AddTablePanel extends javax.swing.JDialog {

    private static boolean is_component_visible = false;

    /**
     * Creates new form AddTablePanel
     */
    public AddTablePanel() {
        initComponents();

        // center the component
        project.jpdftools.toolkit.Toolkit.centerWindow(this, this.getHeight(), this.getWidth());
        this.setAlwaysOnTop(true);

        // indicate that the frame is visible
        is_component_visible = true;
        LoggerManager.getLogger().log(Level.INFO, "Frame shown \"{0}\".", "AddTablePanel");
    }

    public static boolean IsComponentVisible() {
        return is_component_visible;
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        bt_ok = new javax.swing.JButton();
        bt_cancel = new javax.swing.JButton();
        l_columns = new javax.swing.JLabel();
        l_rows = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        yc_rows = new com.toedter.calendar.JYearChooser();
        yc_columns = new com.toedter.calendar.JYearChooser();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle(LocalizationManager.getCurrent_resource().getString("ADD_TABLE_PANEL_TITLE"));
        setIconImage(Toolkit.getDefaultToolkit().getImage("Data/Icons/Soft Scraps Icons/10.png"));
        setResizable(false);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                AddTablePanel.this.windowClosing(evt);
            }
        });

        bt_ok.setText(LocalizationManager.getCurrent_resource().getString("OK"));
        bt_ok.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_okActionPerformed(evt);
            }
        });

        bt_cancel.setText(LocalizationManager.getCurrent_resource().getString("CANCEL"));
        bt_cancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_cancelActionPerformed(evt);
            }
        });

        l_columns.setText(LocalizationManager.getCurrent_resource().getString("ADD_TABLE_PANEL_COLUMNS"));

        l_rows.setText(LocalizationManager.getCurrent_resource().getString("ADD_TABLE_PANEL_ROWS"));

        yc_rows.setMaximum(500000);
        yc_rows.setValue(1);

        yc_columns.setMaximum(500000);
        yc_columns.setValue(1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 204, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(bt_ok)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(bt_cancel))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(l_columns)
                            .addComponent(l_rows))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(yc_columns, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(yc_rows, javax.swing.GroupLayout.DEFAULT_SIZE, 56, Short.MAX_VALUE))))
                .addContainerGap())
        );

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {yc_columns, yc_rows});

        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(yc_rows, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(l_rows))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(yc_columns, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(l_columns))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 5, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(bt_ok)
                    .addComponent(bt_cancel))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {l_columns, l_rows});

        layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {yc_columns, yc_rows});

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void bt_cancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_cancelActionPerformed
        // close the frame
        this.dispose();
        // indicate that the frame is hidden
        is_component_visible = false;
        LoggerManager.getLogger().log(Level.INFO, "Frame hidden \"{0}\".", "AddTablePanel");
    }//GEN-LAST:event_bt_cancelActionPerformed

    private void bt_okActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_okActionPerformed
        // add the table with the selected rows and columns
        JPDFTable table = new JPDFTable(yc_rows.getYear(), yc_columns.getYear());
        MainMenu.getInstance().addObject(table);
        LoggerManager.getLogger().log(Level.INFO, "New table added. Rows = {0}, Columns = {1}. Component ID = {2}",
                new Object[]{yc_rows.getYear(), yc_columns.getYear(), table.getId()});
        // close the frame
        this.dispose();
        // indicate that the frame is hidden
        is_component_visible = false;
    }//GEN-LAST:event_bt_okActionPerformed

    private void windowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_windowClosing
        bt_cancelActionPerformed(null);
    }//GEN-LAST:event_windowClosing
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton bt_cancel;
    private javax.swing.JButton bt_ok;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JLabel l_columns;
    private javax.swing.JLabel l_rows;
    private com.toedter.calendar.JYearChooser yc_columns;
    private com.toedter.calendar.JYearChooser yc_rows;
    // End of variables declaration//GEN-END:variables
}
